package com.example.coreshopapp.task;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;

import com.example.coreshopapp.app.Constants;
import com.example.coreshopapp.http.AccessNet;

import okhttp3.RequestBody;

public class ClassBillTask {
    private Handler outHandler;

    public void setHandler(Handler handler) {
        outHandler = handler;
    }
    private RequestBody requestBody;

    public ClassBillTask(RequestBody requestBody) {
        this.requestBody = requestBody;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Message message = outHandler.obtainMessage();
            switch (msg.what) {
                case 9900:
                    message.what = 9900;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
                case 9901:
                    message.what = 9901;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
                case 9902:
                    message.what = 9901;
                    message.obj = "操作异常，请重试";// info;
                    outHandler.sendMessage(message);
                    break;
                case 9904:
                    message.what = 9904;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
            }
        }
    };

    private boolean freshNetData() {
        new Thread(() -> {
            boolean b = AccessNet.postFormDataNet(mHandler, Constants.urlClass.class_bill,6,requestBody);
        }).start();
        return true;
    }

    public Boolean execute() {
        return freshNetData();
    }
}
